<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

class Pay extends Controller
{
    public function __construct()
    {
        parent::__construct();
        if(!session('name')){
            $this->redirect("/admin/login/login");
        }
    }
    public function index(){
        $payList=Db::name('pay')->select();
        foreach ($payList as $k=>$v){
            $payList[$k]['book']=Db::name('book')->find($v['pay_book_id']);
            $payList[$k]['user']=Db::name('user')->find($v['pay_user_id']);
        }
        $this->assign('payList',$payList);
        return $this->fetch();
    }
    public function saveexpress(){
        if(request()->isPost()){
            $payId=input('param.pay_id');
            $pay_express=input('param.pay_express');
            $res=(new \app\common\model\Pay())->where('pay_payed',1)->where('pay_id',$payId)->find();
            if($res){
                $res->save(['pay_state'=>1,'pay_express'=>$pay_express]);
                if($res){
                    return "发货成功";
                }else{
                    return "发货失败";
                }
            }else{
                return "当前订单未支付";
            }
        }
        $payId=input('param.pay_id');
        $this->assign('payId',$payId);
        return $this->fetch();
    }
}
